#define  _CRT_SECURE_NO_WARNINGS


struct ListNode {
    int val;
    struct ListNode* next;
    ListNode(int x) : val(x), next(nullptr) {}
};

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* dummy = new ListNode(-1);
        ListNode* cur = dummy;
        ListNode* left = head, * right = head;

        while (right)
        {
            while (right && right->val == left->val)
                right = right->next;
            cur->next = left;
            cur = left;
            left = right;
        }
        cur->next = nullptr;
        ListNode* newHead = dummy->next;
        delete dummy;
        return newHead;
    }
};

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* cur = head;

        while (cur && cur->next)
        {
            if (cur->val == cur->next->val)
            {
                ListNode* tmp = cur->next;
                cur->next = cur->next->next;
                delete tmp;
            }
            else
                cur = cur->next;
        }
        return head;
    }
};